// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use tauri::command;

use chrono::prelude::*;
// use tauri_plugin_log::{LogLevel, };


// #[derive(Debug, Deserialize)]
// pub struct RequestBody {
//   id: i32,
//   name: String,
// }

#[command]
pub fn log_operation(event: String, payload: Option<String>) {
  println!("{} {:?}", event, payload);
}

// #[command]
// pub fn perform_request(endpoint: String, body: RequestBody) -> String {
//   println!("{} {:?}", endpoint, body);
//   "message response".into()
// }

#[command]
pub async fn greet(name: String, age: u8) -> String {
  // tauri_plugin_log::logyyy(
  //   LogLevel::Debug,
  //   format!("start calling greet name={}", name),
  // );

  //tauri_plugin_sqlite::character_create().await;

  // tauri_plugin_log::logzzz(
  //   LogLevel::Debug,
  //   format!("start calling greet name={}", name),
  // );

  //tauri_plugin_sqlite::character_count().await;

  // let gres :Option<String>= graphql::gsample().await;

  // tauri_plugin_log::logzzz(
  //   LogLevel::Debug,
  //   format!("gsample gres={:?}", gres),
  // );

  let port = actix_graphql::get_port();
  let dt = Local::now();

  // implicit return, because no semicolon!
  format!(
    "Hello {}, {} year-old human! @{}, port={}",
    name,
    age,
    dt.format("%Y-%m-%d %H:%M:%S").to_string(), port
  )
}

#[command]
pub fn log111(message: String) -> String {
  // tauri_plugin_log::logyyy(
  //   tauri_plugin_log::LogLevel::Info,
  //   format!("log111 calling Log-Plugin-Method: {}", message),
  // );

  "".into()
}

#[command]
pub async fn get_actix_graphql_endpoint() -> String {
//  let endpoint = format!("https://localhost:{}/v1",actix_graphql::get_port());
 let endpoint = format!("http://localhost:{}/v1",actix_graphql::get_port());

 println!("get_actix_graphql_endpoint=====================endpoint={}",endpoint);
 
 endpoint
}

